//---------------------------------------------------------------------------

#ifndef XComplexH
#define XComplexH

#include <Classes.hpp>
//---------------------------------------------------------------------------

enum cxMode {cxmCart, cxmPolar };
enum cxAngle {cxaDeg, cxaRad, cxaDag };
enum cxStyle {cxsDef, cxsCie, cxsEng };

typedef /*long*/ double TCxType;

class TXComplex
{
private:
    TCxType r;
    TCxType j;
    cxMode mode;
    cxAngle ang;
    cxStyle style;
    int pres; //precision

protected:
    TCxType __fastcall GetMod(void);
    void __fastcall SetMod(TCxType m);
    TCxType __fastcall GetAng(void);
    void __fastcall SetAng(TCxType a);
    bool __fastcall GetCX(void);

    AnsiString __fastcall ToFormat(TCxType v, char symb);
    AnsiString __fastcall DecodeNum(AnsiString t, int *l, int *e, bool *s);

public:
    __fastcall TXComplex();
    __fastcall TXComplex(TCxType real, TCxType img);
//    __fastcall ~TXComplex();

    void __fastcall SetMode(cxMode m);
    void __fastcall SetPrecision(int p);
    void __fastcall SetAngle(cxAngle a);
    void __fastcall SetStyle(cxStyle s);

    TXComplex __fastcall operator=(TXComplex v);
    TXComplex __fastcall operator=(TCxType v);
    TXComplex __fastcall operator+(TXComplex v);
    TXComplex __fastcall operator+=(TXComplex v);
    TXComplex __fastcall operator-(TXComplex v);
    TXComplex __fastcall operator-=(TXComplex v);
    TXComplex __fastcall operator/(TXComplex v);
    TXComplex __fastcall operator/=(TXComplex v);
    TXComplex __fastcall operator*(TXComplex v);
    TXComplex __fastcall operator*=(TXComplex v);

    bool __fastcall operator==(TXComplex v);
    bool __fastcall operator==(TCxType v);
    bool __fastcall operator!=(TXComplex v);
    bool __fastcall operator!=(TCxType v);

    TXComplex __fastcall sqrt(void);
    TXComplex __fastcall pow(double p);
    TXComplex __fastcall inv(void);
    TXComplex __fastcall op(void);
    TXComplex __fastcall conj(void);
    TXComplex __fastcall log(double b);

    AnsiString __fastcall ToStr(bool force);

    __property TCxType R = {read=r, write=r};
    __property TCxType J = {read=j, write=j};
    __property TCxType M = {read=GetMod, write=SetMod};
    __property TCxType A = {read=GetAng, write=SetAng};
    __property bool IsComplex = {read=GetCX};
};

#endif
